package com.magnusart.scrumppm.model;

import static com.magnusart.scrumppm.model.States.Transition.CHOOSER_TO_DETAILS;
import static com.magnusart.scrumppm.model.States.Transition.CHOOSER_TO_NEW;
import static com.magnusart.scrumppm.model.States.Transition.DETAILS_TO_CHOOSER;
import static com.magnusart.scrumppm.model.States.Transition.NEW_TO_DETAILS;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.Observable;
import java.util.Observer;

import org.junit.Test;

import com.magnusart.scrumppm.model.States;
import com.magnusart.scrumppm.model.States.Transition;

public class StateMachineSpec implements Observer
{

	@Test
	public void stateAShouldGoToStateB() throws Exception {
		// Observer the state machine
		States.observe().addObserver( this );
		
		assertEquals( States.PROJECT_CHOOSER, States.currentState() );
		assertTrue( Transition.to( CHOOSER_TO_NEW ) );
		assertFalse( Transition.to( CHOOSER_TO_DETAILS ) );
		assertEquals( States.PROJECT_CREATE_NEW, States.currentState() );
		assertTrue( Transition.to( NEW_TO_DETAILS ) );
		assertTrue( Transition.to( DETAILS_TO_CHOOSER ) );
		assertEquals( States.PROJECT_CHOOSER, States.currentState() );
	}

	@Override
	public void update( Observable obs, Object obj ) {
		assertTrue( obj instanceof Transition );	
	}
	
	
}
